home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / aros / source / exec / memory / src / freepooled.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-16  |  2.2 KB  |  105 lines

  1. /*
  2.     (C) 1995 AROS - The Amiga Replacement OS
  3.     $Id: freepooled.c 1.1 1995/11/14 22:31:07 digulla Exp digulla $
  4.     $Log: freepooled.c $
  5.  * Revision 1.1  1995/11/14  22:31:07  digulla
  6.  * Initial revision
  7.  *
  8.     Desc:
  9.     Lang: english
  10. */
  11. #include "exec_intern.h"
  12. #include "memory.h"
  13.  
  14. /*****************************************************************************
  15.  
  16.     NAME */
  17.     #include <exec/memory.h>
  18.     #include <clib/exec_protos.h>
  19.  
  20.     __AROS_LH3(void, FreePooled,
  21.  
  22. /*  SYNOPSIS */
  23.     __AROS_LA(APTR         , poolHeader, A0),
  24.     __AROS_LA(APTR         , memory, A1),
  25.     __AROS_LA(unsigned long, memSize, D0),
  26.  
  27. /*  LOCATION */
  28.     struct ExecBase *, SysBase, 119, Exec)
  29.  
  30. /*  FUNCTION
  31.     Free memory allocated out of a private memory pool.
  32.  
  33.     INPUTS
  34.     poolHeader - Handle of the memory pool
  35.     memory       - Pointer to the memory
  36.     memSize    - Size of the memory chunk
  37.  
  38.     RESULT
  39.  
  40.     NOTES
  41.  
  42.     EXAMPLE
  43.  
  44.     BUGS
  45.  
  46.     SEE ALSO
  47.     CreatePool(), DeletePool(), AllocPooled()
  48.  
  49.     INTERNALS
  50.  
  51.     HISTORY
  52.     16-10-95    created by M. Fleischer
  53.     26-10-95    digulla adjusted to new calling scheme
  54.  
  55. ******************************************************************************/
  56. {
  57.     __AROS_FUNC_INIT
  58.     struct Pool *pool=(struct Pool *)poolHeader;
  59.  
  60.     /* If memSize is bigger than the ThreshSize it's allocated seperately. */
  61.     if(memSize>pool->ThreshSize)
  62.     {
  63.     struct Block *bl;
  64.  
  65.     /* Get pointer to header */
  66.     bl=(struct Block *)((UBYTE *)memory-BLOCK_TOTAL);
  67.  
  68.     /* Remove it from the list */
  69.     Remove((struct Node *)&bl->Node);
  70.  
  71.     /* And Free the memory */
  72.     FreeMem(bl,bl->Size);
  73.     }else
  74.     {
  75.     /* Look for the right MemHeader */
  76.     struct MemHeader *mh=(struct MemHeader *)pool->PuddleList.mlh_Head;
  77.  
  78.     for(;;)
  79.     {
  80.         /* The memory must be between the two borders */
  81.         if(memory>=mh->mh_Lower&&memory<mh->mh_Upper)
  82.         {
  83.         /* Found the MemHeader. Free the memory. */
  84.         Deallocate(mh,memory,memSize);
  85.  
  86.         /* Is this MemHeader completely free now? */
  87.         if(mh->mh_Free==pool->PuddleSize)
  88.         {
  89.             /* Yes. Remove it from the list. */
  90.             Remove(&mh->mh_Node);
  91.  
  92.             /* And free it. */
  93.             FreeMem(mh,pool->PuddleSize+sizeof(struct MemHeader));
  94.         }
  95.         /* All done. */
  96.         break;
  97.         }
  98.         /* Try next MemHeader */
  99.         mh=(struct MemHeader *)mh->mh_Node.ln_Succ;
  100.     }
  101.     }
  102.     __AROS_FUNC_EXIT
  103. } /* FreePooled */
  104.  
  105.